package com.example.event;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

/**
 * 实现事件发布者（common 模块）
 */
@Component
@RequiredArgsConstructor
public class EventPublisher {
    private final ApplicationEventPublisher publisher;

    public void publishEvent(String moduleName, Object payload) {
        publisher.publishEvent(new ModuleEvent(this, moduleName, payload));
    }

    public void publishGenericEvent(Object payload) {
        publisher.publishEvent(new GenericEvent<>(this, payload));
    }
}